import { defineStore } from 'pinia'
import { getShopMarketAll, findShopMarketAndShareByParam, findShopListByParam, findShopMarketByParam, getOrganizesUser, getOrganizes } from '@/api/system'
import { findWarehouseListByParam } from '@/api/warehouse'

const useBaseDataStore = defineStore('base-info', {
  state: () => {
    return {
      markedtList: [] as any[],
      shopListAndShare: [] as any[],
      shopList: [] as any[],
      userList: [] as any[],
      warehouseList: [] as any[],
      sellersList: [] as any[],
      deptList: [] as any[],
    }
  },
  actions: {
    // 获取站点
    async getMarketList() {
      if (this.markedtList.length) return
      const res: any = await getShopMarketAll()
      this.markedtList = res?.data || []
    },
    // 获取店铺+共享
    async getShopListAndShare() {
      if (this.shopListAndShare.length) return
      const res: any = await findShopMarketAndShareByParam()
      this.shopListAndShare = res?.data || []
    },
    // 获取店铺
    async getShopList() {
      if (this.shopList.length) return
      const res: any = await findShopMarketByParam()
      this.shopList = res?.data || []
    },
    // 获取店铺-不区分站点
    async getSellersList() {
      if (this.sellersList.length) return
      const res: any = await findShopListByParam()
      this.sellersList = res?.data || []
    },
    // 获取所有用户列表
    async getUserList() {
      if (this.userList.length) return
      const res: any = await getOrganizesUser({
        pageNum: 1,
        pageSize: 1000,
      })
      this.userList = res?.data?.records || []
    },
    // 获取仓库列表
    async getWareHouseList() {
      if (this.warehouseList.length) return
      const res: any = await findWarehouseListByParam()
      this.warehouseList = res?.data || []
    },
    // 获取组织架构
    async getDeptList() {
      if (this.deptList.length) return
      const res: any = await getOrganizes()
      this.deptList = res?.data || []
    },
  },
})

export default useBaseDataStore
